import Vue from 'vue'
import Router from 'vue-router'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import 'view-design/dist/styles/iview.css';
import {post,fetch2,patch,put,exportExcel,post2,postAsync,postAsync2,fetch3,postEncrypt} from './utils/http'
import {qweb} from './utils/qwebchannel'
import 'element-ui/lib/theme-chalk/index.css';
import elDragDialog from './utils/el-drag-dialog' // 引入移动事件（el-drag-dialog.js的内容为上面的代码块）
//import Print from './utils/print'
import global_ from './components/Global'//引用文件
import { VueJsonp } from 'vue-jsonp' 
import './plugins/VueQuillEditor.js'
import 'font-awesome/css/font-awesome.min.css'

import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
import * as echarts from 'echarts'

import {registerMicroApps,runAfterFirstMounted, setDefaultMountApp, start} from 'qiankun';
import fetch from 'isomorphic-fetch';
import { DatePicker,TimePicker  } from 'view-design';
Vue.component('DatePicker', DatePicker);
Vue.component('TimePicker', TimePicker);
import ElementUI from 'element-ui';
//import { Button, Select,Row,Container,Icon,Radio,Checkbox,Input,InputNumber,Cascader,Upload,Form,Table,Tree,Pagination,Loading,Message,MessageBox,Notification,Menu,Submenu,Tabs,Dropdown,Steps,Dialog,Card,Carousel,Image,Drawer } from 'element-ui';

import 'xe-utils'
import VueSignature from 'vue-signature-simple'
import previewImg from 'vue-preview-img'
import '../node_modules/vue-preview-img/lib/vue-preview-img.css'

import animate from 'animate.css'
import Print from './assets/vue-print-nb'
import * as uni from './utils/uni.webview.1.5.2.js'
import vueEsign from 'vue-esign'
import Tui from '@wocwin/t-ui'

//codemirror
import VueCodemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
Vue.use(VueCodemirror)

Vue.use(vueEsign)
Vue.use(Tui)
document.addEventListener("UniAppJSBridgeReady", function() {  
    console.log(JSON.stringify(uni))
    Vue.prototype.myUni = uni  
});
Vue.use(Print)
Vue.use(animate)

Vue.use(previewImg)
Vue.use(VueSignature)

Vue.use(VueJsonp)

Vue.use(ElementUI)
/*
Vue.use(Button)
Vue.use(Select)
Vue.use(Row)
Vue.use(Container)
Vue.use(Icon)
Vue.use(Radio)
Vue.use(Checkbox)
Vue.use(Input)
Vue.use(InputNumber)
Vue.use(Cascader)
Vue.use(Upload)
Vue.use(Form)
Vue.use(Table)
Vue.use(Tree)
Vue.use(Pagination)
Vue.use(Menu)
Vue.use(Tabs)
Vue.use(Dropdown)
Vue.use(Steps)
Vue.use(Dialog)
Vue.use(Card)
Vue.use(Carousel)
Vue.use(Image)
Vue.use(Drawer)
Vue.use(Submenu)
*/
Vue.prototype.$echarts = echarts

import md5 from 'js-md5';
Vue.prototype.$md5 = md5;

Vue.use(Viewer);
Viewer.setDefaults({
  Options: { "inline": true, "button": true, "navbar": true, "title": true, "toolbar": true, "tooltip": true, "movable": true, "zoomable": true, "rotatable": true, "scalable": true, "transition": true, "fullscreen": true, "keyboard": true, "url": "data-source" }
});

//定义全局变量
Vue.prototype.$exportExcel=exportExcel;
Vue.prototype.$post=post;
Vue.prototype.$postAsync=postAsync;
Vue.prototype.$postAsync2=postAsync2;
Vue.prototype.$postEncrypt=postEncrypt;
Vue.prototype.$post2=post2;
Vue.prototype.$fetch=fetch;
Vue.prototype.$fetch3=fetch3;
Vue.prototype.$patch=patch;
Vue.prototype.$put=put;
Vue.prototype.$qweb=qweb;
Vue.config.productionTip = false
Vue.prototype.GLOBAL = global_//挂载到Vue实例上面

Vue.directive('el-drag-dialog', elDragDialog);//添加标签事件绑定 可以放大移动弹窗
//弹窗默认点击遮罩改为不关闭 为了防止和拖拽冲突 ，这句需要放在use ElementUI之前（也可以不加这句，自己测试区别）
ElementUI.Dialog.props.closeOnClickModal.default = false;
//Vue.use(Print);  //注册


const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
// 路由守卫
router.beforeEach((to,from,next)=>{
  console.log(to,"to=================");
  console.log(from,"from-----------------")
  if(to.matched.some(res=>res.meta.isLogin)){//判断是否需要登录
    //  alert(sessionStorage.getItem("token"));
      if (sessionStorage.getItem("token")&&sessionStorage.getItem("token")!="null") {
          next();
      }else{
          if(localStorage.getItem("isApp")=='Y'){
            next({
              path:"/login",
              query:{
                  sCode:localStorage.getItem("sCode"),
                  isApp:"Y",
                  isAppTop:"Y",
                  filenames:localStorage.getItem("filenames")
              }
          });
          }else{
            next({
              path:"/login",
              query:{
                  sCode:localStorage.getItem("sCode")
              }
          });
          }
          
      }

  }else{
      next()
  }
});

function genActiveRule(routerPrefix) {
  return location => location.pathname.startsWith(routerPrefix);
}
const request = url =>
  fetch(url, {
    referrerPolicy: 'origin-when-cross-origin',
  });

//注册子应用
registerMicroApps([
  {
    name: 'csvueReport',
    entry: '//8.136.193.200:15555',
    container:"#childs",
    activeRule:'/#/reportChild/bygGmReport'
  },
],
{
  beforeLoad: [
    app => {
      console.log('before load', app);
    },
  ],
  beforeMount: [
    app => {
      console.log('before mount', app);
    },
  ],
  afterMount: [
    app => {
      console.log('after mount', app);
    },
  ],
  afterUnmount: [
    app => {
      console.log('after unload', app);
      app.render({appContent: '', loading: false});
    },
  ],
},

);
let option = { prefetch: false }
start({
  sandbox: { strictStyleIsolation: true } //开启shadow dom沙箱隔离
});
//start({ prefetch: true });

new Vue({
  router,
  store,
  axios,
  render: h => h(App)
}).$mount('#app')